package com.zhixue.auth.controller;

import com.zhixue.ucenter.mapper.ZxUserMapper;
import com.zhixue.ucenter.model.po.ZxUser;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author Dragon
 * @description LoginController
 * @date 2023/10/13 12:07
 */
@Slf4j
@RestController
public class LoginController {

    @Autowired
    ZxUserMapper userMapper;

    @RequestMapping("/login-success")
    public String loginSuccess(){

        return "登录成功";
    }


    @RequestMapping("/user/{id}")
    public ZxUser getuser(@PathVariable("id") String id){
        ZxUser zxUser = userMapper.selectById(id);
        return zxUser;
    }

    @RequestMapping("/r/r1")
    @PreAuthorize("hasAuthority(p1)")  //拥有P1权限方可访问
    public String r1(){
        return "访问r1资源";
    }

    @RequestMapping("/r/r2")
    @PreAuthorize("hasAuthority(p2)")  //拥有P2权限方可访问
    public String r2(){
        return "访问r2资源";
    }



}
